﻿<script type="text/javascript">
    $.extend($.fn.validatebox.defaults.rules, {
        /*必须和某个字段相等*/
        equalTo: {
            validator: function (value, param) {
                return $(param[0]).val() == value;
            },
            message: '字段不匹配'
        }

    });
    //新增
    function submitAddForm() {
        var isValid = $("#NewUserList").form("validate");
        if (isValid) {
            $('#btnadd').linkbutton('disable');
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/DM/User/UserAdd")',
                data:
                    {
                        Info: JSON.stringify(UserModel(false))
                    },
                dataType: "json",
                success: function (jsData) {
                    $.handleJsonResult(jsData, function () {
                        $('#NewUserList').dialog("close");
                        $("#tbList").datagrid("reload");
                    }, function () {
                        $('#btnadd').linkbutton('enable');
                    });
                }
            });
        } else {
            $.showMsg("请填写必填项！", "提示");
        }
    }
    //修改
    function submitEditForm() {
        $.messager.confirm('提示', '确认修改该数据?', function (r) {
            if (r) {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Content("~/DM/User/UserEdit")',
                    data:
                        {
                            Info: JSON.stringify(UserModel(true))
                        },
                    dataType: "json",
                    success: function (jsData) {
                        $.handleJsonResult(jsData, function () {
                            $('#NewUserList').dialog("close");
                            $("#tbList").datagrid("reload");
                        });
                    }
                });
            }
        });
    }

    //获取填写所有值
    function UserModel(isEdit) {
        var obj = new Object();
        if (isEdit)
            obj.ID = $('#EID').val();
        else
            obj.PassWord = $("#EPassWord").val();
        obj.DepID = $("#EDepID").combotree('getValue');
        obj.LoginName = $("#ELoginName").textbox('getText');
        obj.WorkCode = $("#EWorkCode").textbox('getText');
        obj.Name = $("#EName").textbox('getText');
        obj.Gender = $("#EGender").combobox('getValue');
        obj.SN = $("#ESN").numberbox('getValue');
        obj.PhysicianCode = $("#PhysicianCode").textbox('getText');  //add2021-10-15 plq 医保上线移植
        return obj;
    }
    ////新增入口
    //function initAddInfo() {
    //    //将修改按钮禁用
    //    $('#btnedit').linkbutton('disable');
    //    $.GID("btnedit").style.display = "none";
    //    $('#btnadd').linkbutton('enable');
    //    $.GID("btnadd").style.display = "block";
    //    $('#ID').val("");
    //    $('#DepID').val("");
    //    $("#Name").textbox('clear');
    //    $("#SN").numberbox("clear");
    //    $("#LoginName").textbox('clear');
    //    $("#WorkCode").textbox('clear');
    //    $("#IsActive").combobox("setText", "是");
    //    $("#Gender").combobox("setText", "男");
    //    $("#PassWord").textbox('clear');
    //}
    //function initUpdateInfo() {
    //    $('#btnadd').linkbutton('disable');
    //    $.GID("btnadd").style.display = "none";
    //    $('#btnedit').linkbutton('enable');
    //    $.GID("btnedit").style.display = "block";

    //}
    function ValidateValue(textbox) {
        var IllegalString = "[`~!#$^&*()=|{}':;',\\[\\].<>/?~！#￥……&*（）——|{}【】‘；：”“'。，、？]‘' -_+";
        var textboxvalue = textbox.value;
        if (textboxvalue == "") { //add2021-05-25 plq 优化输入检测，当退格为空时，不弹出alert框
            return false;
        }
        var index = textboxvalue.length - 1;
        //console.log(index);
        var s = textbox.value.charAt(index);
        //console.log(s);
        if (IllegalString.indexOf(s) >= 0) {
            s = textboxvalue.substring(0, index);
            textbox.value = s;
            $.messager.alert('提示', '不允许输入特殊字符', function () {
            });
        }
    }
    $(function () {
        $('#ELoginName').textbox('textbox').bind('keyup', function () {
            ValidateValue(this);
        });
        $('#EWorkCode').textbox('textbox').bind('keyup', function () {
            ValidateValue(this);
        });
        $('#EName').textbox('textbox').bind('keyup', function () {
            ValidateValue(this);
        });
        $('#ESN').textbox('textbox').bind('keyup', function () {
            ValidateValue(this);
        });
    });

</script>

<div id="NewUserList" class="easyui-dialog" title="人员编辑" data-options="modal:true,collapsible:false,minimizable:false,maximizable:false,closed:true,resizable:false,iconCls:'icon-custom-cWuZiWeiHu'" style="width:550px;height:440px;padding:10px;">
    <table>
        <tr style="height: 30px">
            <td style="width: 100px">部门：</td>
            <td>
                <input id="EDepID" class="easyui-combotree" style="width:180px;">
                <input id="EID" type="hidden" />
            </td>
        </tr>

        <tr style="height: 30px">
            <td style="width: 100px">登录名：</td>
            <td>
                <input id="ELoginName" class="easyui-textbox" style="width:160px" data-options="required:true" />
            </td>
        </tr>
        <tr style="height: 30px" id="trPwd">
            <td style="width: 100px">密码：</td>
            <td>
                <input type="password" id="EPassWord" class="easyui-validatebox" style="width:160px" data-options="required:true" onkeyup="ValidateValue(this)" />
            </td>
        </tr>
        <tr style="height: 30px" id="trPwdRepeat">
            <td style="width: 100px">重复密码：</td>
            <td>
                <input type="password" id="ERePassWord" class="easyui-validatebox" style="width:160px" data-options="required:true"
                       validtype="equalTo['#EPassWord']" invalidmessage="两次输入密码不匹配" onkeyup="ValidateValue(this)" />
            </td>
        </tr>
        <tr style="height: 30px">
            <td style="width: 100px">工号：</td>
            <td>
                <input id="EWorkCode" class="easyui-textbox" style="width:160px" data-options="required:true" />
            </td>
        </tr>
        <tr style="height: 30px">
            <td style="width: 100px">姓名：</td>
            <td>
                <input id="EName" class="easyui-textbox" style="width:160px" data-options="required:true" onkeyup="ValidateValue(this)" />
            </td>
        </tr>
        <tr style="height: 30px ">
            <td style="width: 100px">性别：</td>
            <td>
                <select class="easyui-combobox" style="width: 160px" id="EGender" data-options="required:true,panelHeight:70, editable:false">
                    <option value="男">男</option>
                    <option value="女">女</option>
                </select>
            </td>
        </tr>
        <tr style="height: 30px">
            <td style="width: 100px ">顺序号：</td>
            <td>
                <input id="ESN" class="easyui-numberbox" style="width:160px" data-options="required:true" value="255" onkeyup="ValidateValue(this)" />

            </td>
        </tr>
        <tr style="height: 30px">
            <td style="width: 100px">医师编号：</td>
            <td>
                <input id="PhysicianCode" class="easyui-textbox" style="width:160px" />
            </td>
        </tr>

        <tr><td></td></tr>
        <tr><td></td></tr>
        <tr><td></td></tr>
        <tr style="height:30px">
            <td colspan="5" align="center">
                <a href="javascript:void(0)" id="btnedit" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="submitEditForm();">确认修改</a>
                <a href="javascript:void(0)" id="btnadd" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="submitAddForm();">确认新增</a>
            </td>
        </tr>
    </table>

</div>
